package com.zhima.function;

import com.zhima.panel.RandomInDataConfiguration;

import java.awt.*;
import java.util.List;
import java.util.function.Consumer;

public class RemoveSelectedRow implements Consumer<Integer> {
    private final List<RandomInDataConfiguration> rows;
    private final Container contentPane;

    public RemoveSelectedRow(List<RandomInDataConfiguration> rows, Container contentPane) {
        this.rows = rows;
        this.contentPane = contentPane;
    }

    @Override
    public void accept(Integer integer) {
        if (integer >= rows.size()) {
            return;
        }
        RandomInDataConfiguration comp = rows.get(integer);
        contentPane.remove(comp);
        rows.remove(integer.intValue());
        for (int i = 0; i < rows.size(); i++) {
            rows.get(i).setRowIndex(i);
        }
        contentPane.revalidate();
    }
}